#pragma once

using namespace std;

class Grid{
private:
    int dim;            // 网格维度
    int n;              // 分隔数
public:
    vector<vector<double>> grid2D;      // 二维网格
    vector<double> grid1D;              // 一维网格
    Grid(int d, int N){
        dim = d;
        n = N;
        if(d == 1){                     // 一维网格
            double delta = 1.0 / n;
            for(int i = 0; i <= n; i++){
                double x = i * delta;
                grid1D.push_back(x);
            }
        }else if(d == 2){               // 二维网格
            double delta = 1.0 / n;
            for(int i = 0; i <= n; i++){
                vector<double> row;
                for(int j = 0; j <= n; j++){
                    double x = i * delta;
                    double y = j * delta;
                    row.push_back(x);
                    row.push_back(y);
                }
                grid2D.push_back(row);
            }
        }else{                          // 非法维度
            cout << "Error: unsupported dimension." << endl;
        }
    }
    
    void display(){
        if(dim == 1){                   // 显示一维网格
            for(int i=0; i<grid1D.size(); i++){
                cout << grid1D[i] << " ";
            }
            cout << endl;
        }else if(dim == 2){             // 显示二维网格
            for(int i=0; i<grid2D.size(); i++){
                for(int j=0; j<grid2D[i].size(); j++){
                    cout << grid2D[i][j] << " ";
                }
                cout << endl;
            }
        }
    }
};
